
init()
function init() {
  document.addEventListener('DOMNodeInserted', function (e) {

    ProccessArticle(e)
    ProccessDown(e);
  })
  document.addEventListener("readystatechange", function () {
    switch (document.readyState) {
      case "loading":
        // 表示文档还在加载中，即处于“正在加载”状态。
        break;
      case "interactive":
        // 文档已经结束了“正在加载”状态，DOM元素可以被访问。


        break;
      case "complete":
        // 页面所有内容都已被完全加载.
        break;
    }
  })
}

function getCoverImg(imgDom) {
  let a = imgDom.attributes['ess-data'] || imgDom.attributes['src-data']
  if (a && (a.value.indexOf('.jpg') != -1 || a.value.indexOf('.jpeg') != -1)) {
    return a.value;
  }
  return null;
}

function transHtml(body) {
  let dom = body.querySelector('.tpc_content.do_not_catch');
  let html = '';
  let pics = [];
  let links = [];
  dom.querySelectorAll("img").forEach(v => {
    let imgSrc = getCoverImg(v)
    if (imgSrc) {
      let img = new Image()
      img.src = imgSrc;
      img.style = "max-width:800px"
      //img.setAttribute('data-link', v.attributes['data-link'].value);
      img.attributes['data-link'] = v.attributes['data-link'];
      img.onload = tryBigImg
      pics.push(img.outerHTML)
    }

  })
  dom.querySelectorAll("a").forEach(v => {
    if (v.href.indexOf("rmdown") != -1) {

      links.push(`<a href="${v.href}">${v.href}</a>`)
    }
  })
  html += pics.join('');
  html += `<br/>` + links.join('');
  document.write('');
  document.open()
  document.write(buildADSpy() + html);
  document.close()
}

async function tryBigImg(e) {
  // var img = e.target;
  // let imgBad = img.attributes['data-link'].value;
  // axios({
  //     method: 'get',
  //     url: imgBad,
  // })
  //     .then(function (response) {
  //         debugger
  //         console.log(response);
  //     })
  //     .catch(function (error) {
  //         console.log(error);
  //     });

}
function buildADSpy() {
  let h = "";
  h += `<div class="tips" style="top:px;display:block;height:px"><table style="margin-left:0px"></table></div>`
  h += `<div class="sptable_do_not_remove" style="left:px;opacity:1;display:block;" ><table> <td  onclick="javascript:void(0)">e2rtfdr</td></table></div>`
  return h;
}

function ProccessArticle(e) {
  if (window.location.href.indexOf('htm_data') > 0) {
    var temBody = document.createElement('div');
    let body = (e.path[2].body || e.path[3].body)
    temBody.appendChild(body);

    document.head.innerHTML = "";
    document.write("")
    document.close();
    var httpMeta = document.createElement('meta');
    httpMeta.content = "upgrade-insecure-requests";
    httpMeta.setAttribute("http-equiv", "Content-Security-Policy");
    document.head.appendChild(httpMeta)
    transHtml(temBody);
  }
}
function ProccessDown() {
  if (location.href.indexOf('rmdown.com/link.php') > -1) {
    document.body.querySelectorAll("img").forEach(v => {
      v.remove()
    })
  }
}
console.log('XXXXXXXXXXXXXXXXXXXX windbell2')

